<template>
    <h3 style="text-align: :center;">添加投资信息</h3>
    <table class="table-bordered" border="1">
        <tr>
            <td>投资名称</td>
            <td>
                <input type="text" v-model="I_Name" />
            </td>
        </tr>
        <tr>
            <td>投资总额度</td>
            <td>
                <input type="text" v-model="I_Budget" />
            </td>
        </tr>
        <tr>
            <td style="text-align: :center;" colspan="2">
                <input type="button" value="添加" @click="addInvestment" class="btn btn-success" />
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import 'bootstrap/dist/css/bootstrap.min.css'
import 'bootstrap/dist/js/bootstrap.min.js'
import axios from 'axios';
import { ref } from 'vue';
import { useRouter } from 'vue-router';


//定义变量
const I_Name = ref('');
const I_Budget = ref();

//添加信息函数
const addInvestment = () => {
    //判断非空
    if (!I_Name.value) {
        alert('投资名称不能为空');
        return;
    }
    if (!I_Budget.value) {
        alert('投资金额不能为空');
        return;
    }

    if (I_Budget.value < 0 || I_Budget.value > 100000000) {
        alert('投资金额需大于0且小于1亿元');
        return;
    }

    axios.post("https://localhost:44305//api/Invests/AddInvestInfo",
        {
            I_Name: I_Name.value,
            I_Budget: I_Budget.value
        })
        .then(res => {
            if (res.data > 0) {
                alert('投资成功！');
                RouteView();
            }
            else {
                alert('投资失败！');
            }
        })
        .catch(error => {
            console.log(error);
        })
}

//路由跳转函数
const router = useRouter();
const RouteView = () => {
    router.push('/ShowInvestPage');
}

</script>

